package cn.ante.mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class DelayProduct {
    public static void main(String[] args) throws Exception {
        // 创建生产者协
        DefaultMQProducer producer = new DefaultMQProducer("delay_producer");

        // 连接nameserver
        producer.setNamesrvAddr("127.0.0.1:9876");

        //开启生产者
        producer.start();

        // 设置消息的主题、标签、内容等
        Message message = new Message("order", "delayorder", "我是延迟取消订单".getBytes(StandardCharsets.UTF_8));

        // 设置延迟级别
        message.setDelayTimeLevel(4);
        // 发送消息
        SendResult result = producer.send(message);
        System.out.println(result);

        // 关闭生产者
        producer.shutdown();

    }
}
